package com.dy.排序.内排序.选择排序.直接选择排序;

import java.util.Arrays;
/*
O(n2),不稳定
 */
public class SelectSort {
    public static void selectSort(int[] nums) {
        for (int i = 0; i < nums.length-1; i++) {
            int min = i;
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[j] < nums[min]) {
                    min = j;
                }
            }
            if (min != i) {
                int tmp = nums[min];
                nums[min] = nums[i];
                nums[i] = tmp;
            }
        }
    }

    public static void main(String[] args) {
        int nums[] = {3,2,4,1,2};
        selectSort(nums);
        Arrays.stream(nums).forEach(System.out::println);
    }
}
